# coding=utf-8
# author:xc
# datetime:2018/8/1 13:34
from werkzeug.utils import secure_filename
import sys

reload(sys)
sys.setdefaultencoding('utf8')
import os


def upload(upFile):
    """

    :param upFile: 即将上传的文件
    :param cdn_path: 上传到线上的key
    :return:
    """
    oldname = secure_filename(upFile.filename)
    pcsystem = sys.platform
    # 保存至本地
    if pcsystem.startswith('win'):
        base = 'c:/tmp_upload/'
        if not os.path.exists(base):
            os.makedirs(base)
        upFile.save(os.path.join(base, oldname))
        localPath = base + oldname
    else:
        base = '/home/store'
        if not os.path.exists(base):
            os.makedirs(base)
        upFile.save(os.path.join(base, oldname))
        localPath = "/img/"+oldname
    return localPath
